#region File Description
//-----------------------------------------------------------------------------
// Game.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Microsoft.Xna.Framework.Audio;
using InversPong.Model;
using Microsoft.Xna.Framework.Input;
using InversPong.Model.Levels;
#endregion

namespace InversPong
{
    /// <summary>
    /// Sample showing how to manage different game states, with transitions
    /// between menu screens, a loading screen, the game itself, and a pause
    /// menu. This main game class is extremely simple: all the interesting
    /// stuff happens in the ScreenManager component.
    /// </summary>
    public class PongGame : Microsoft.Xna.Framework.Game
    {
        #region Fields

        GraphicsDeviceManager graphics;
        ScreenManager screenManager;


        // By preloading any assets used by UI rendering, we avoid framerate glitches
        // when they suddenly need to be loaded in the middle of a menu transition.
        static readonly string[] preloadAssets =
        {
            "gradient"
        };

        static readonly string[] preloadSounds = 
        {
            "invulnerability",
            "bombe",
            "escargot",
            "inverse",
            "moteur",
            "rebond",
            "Size_dim",
            "viagra",
            "woosh"
        };

        static readonly int[] screenSize =
        {
            1000,
            800
        };

        Model.Game game;
        #endregion

        #region Initialization
     

        /// <summary>
        /// The main game constructor.
        /// </summary>
        public PongGame()
        {
            Content.RootDirectory = "Content";

            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = screenSize[0];
            graphics.PreferredBackBufferHeight = screenSize[1];

            // Activate the first screens.

            int mapHeight = graphics.PreferredBackBufferHeight - 100;
            int mapWidth = graphics.PreferredBackBufferWidth;


            Player player1 = new Player(Keys.Z, Keys.S, "PLAYER 1");
            Player player2 = new Player(Keys.O, Keys.L, "PLAYER 2");

            Map map = new Map(mapWidth, mapHeight);


            game = new Model.Game(Model.Game.Status.Running, new Intermediate(), player1, player2, map);

            // Create the screen manager component.
            screenManager = new ScreenManager(this, game);

            Components.Add(screenManager);

            screenManager.AddScreen(new BackgroundScreen(), null);
            screenManager.AddScreen(new MainMenuScreen(), null);

            this.Services.AddService(typeof(Services.IMusicPlayer), new Services.SimpleMusicPlayer(this));
            this.Services.AddService(typeof(Services.ISoundPlayer), new Services.SimpleSoundPlayer(this));
            this.Services.AddService(typeof(Services.ISpriteDrawer), new Services.SimpleSpriteDrawer(this));

        }

        /// <summary>
        /// Loads graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            foreach (string asset in preloadAssets)
            {
                Content.Load<object>(asset);
            }

            Services.ISoundPlayer soundPlayer = (Services.ISoundPlayer)Services.GetService(typeof(Services.ISoundPlayer));
            foreach (string s in preloadSounds)
            {
                soundPlayer.Preload(s);
            }
        }


        #endregion

        #region Draw


        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.Black);
            // The real drawing happens inside the screen manager component.
            base.Draw(gameTime);
        }


        #endregion
    }


    #region Entry Point

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static class Program
    {
        static void Main()
        {
            using (PongGame game = new PongGame())
            {
                game.Run();
            }
        }
    }

    #endregion
}
